
var StockPrice = function() {
  this.map = new Map()
  this.time = []
  this.priceList = []
};
const helper = (arr, val) => {
  let l = 0, r = arr.length-1
  while(l < r){
    let m = (l+r) >> 1
    if(arr[m] < val){
      l = m+1
    }else{
      r = m
    }
  }
  if(arr[l] < val){
    arr.splice(l+1, 0, val)
  }else{
    arr.splice(l, 0, val)
  }
}

/** 
 * @param {number} timestamp 
 * @param {number} price
 * @return {void}
 */
StockPrice.prototype.update = function(timestamp, price) {
  const { map, time, priceList } = this
  if(map.has(timestamp)){
    const index = priceList.indexOf(map.get(timestamp))
    priceList.splice(index, 1)
  }
  map.set(timestamp, price)
  helper(time, timestamp)
  helper(priceList, price)
};

/**
 * @return {number}
 */
StockPrice.prototype.current = function() {
  const { map, time } = this
  return map.get(time[time.length-1])
};

/**
 * @return {number}
 */
StockPrice.prototype.maximum = function() {
  return this.priceList[this.priceList.length-1]
};

/**
 * @return {number}
 */
StockPrice.prototype.minimum = function() {
  return this.priceList[0]
};

/**
 * Your StockPrice object will be instantiated and called as such:
 * var obj = new StockPrice()
 * obj.update(timestamp,price)
 * var param_2 = obj.current()
 * var param_3 = obj.maximum()
 * var param_4 = obj.minimum()
 */